home *** CD-ROM | disk | FTP | other *** search
/ Quick PC 61 / Quick PC 61.iso / I386 / PUBPRN.VB_ / pubprn.vbs
Encoding:
Text File  |  2003-02-21  |  3.6 KB  |  133 lines

  1. '----------------------------------------------------------------------
  2. '    pubprn.vbs - publish printers from a non Windows 2000 server into Windows 2000 DS
  3. '    
  4. '
  5. '     Arguments are:-
  6. '        server - format server
  7. '        DS container - format "LDAP:\\CN=...,DC=...."
  8. '
  9. '
  10. '    Copyright (c) Microsoft Corporation 1997
  11. '   All Rights Reserved
  12. '----------------------------------------------------------------------
  13.  
  14. '--- Begin Error Strings ---
  15.  
  16. Dim L_PubprnUsage1_text
  17. Dim L_PubprnUsage2_text
  18. Dim L_PubprnUsage3_text      
  19. Dim L_PubprnUsage4_text      
  20. Dim L_PubprnUsage5_text      
  21. Dim L_PubprnUsage6_text      
  22.  
  23. Dim L_GetObjectError1_text
  24. Dim L_GetObjectError2_text
  25.  
  26. Dim L_PublishError1_text
  27. Dim L_PublishError2_text     
  28. Dim L_PublishError3_text
  29. Dim L_PublishSuccess1_text
  30.  
  31.  
  32. L_PubprnUsage1_text      =   "Usage: [cscript] pubprn.vbs server ""LDAP://OU=..,DC=..."""
  33. L_PubprnUsage2_text      =   "       server is a Windows server name (e.g.: Server) or UNC printer name (\\Server\Printer)"
  34. L_PubprnUsage3_text      =   "       ""LDAP://CN=...,DC=..."" is the DS path of the target container"
  35. L_PubprnUsage4_text      =   ""
  36. L_PubprnUsage5_text      =   "Example 1: pubprn.vbs MyServer ""LDAP://CN=MyContainer,DC=MyDomain,DC=Company,DC=Com"""
  37. L_PubprnUsage6_text      =   "Example 2: pubprn.vbs \\MyServer\Printer ""LDAP://CN=MyContainer,DC=MyDomain,DC=Company,DC=Com"""
  38.  
  39. L_GetObjectError1_text   =   "Error: Path "
  40. L_GetObjectError2_text   =   " not found."
  41. L_GetObjectError3_text   =   "Error: Unable to access "
  42.  
  43. L_PublishError1_text     =   "Error: Pubprn cannot publish printers from "
  44. L_PublishError2_text     =   " because it is running Windows 2000, or later."
  45. L_PublishError3_text     =   "Failed to publish printer "
  46. L_PublishError4_text     =   "Error: "
  47. L_PublishSuccess1_text   =   "Published printer: "
  48.  
  49. '--- End Error Strings ---
  50.  
  51.  
  52. set Args = Wscript.Arguments
  53. if args.count < 2 then
  54.     wscript.echo L_PubprnUsage1_text
  55.     wscript.echo L_PubprnUsage2_text
  56.     wscript.echo L_PubprnUsage3_text
  57.     wscript.echo L_PubprnUsage4_text
  58.     wscript.echo L_PubprnUsage5_text
  59.     wscript.echo L_PubprnUsage6_text
  60.     wscript.quit(1)
  61. end if
  62.  
  63. ServerName= args(0)
  64. Container = args(1)
  65.  
  66.  
  67. on error resume next
  68. Set PQContainer = GetObject(Container)
  69.  
  70. if err then
  71.     wscript.echo L_GetObjectError1_text & Container & L_GetObjectError2_text
  72.     wscript.quit(1)
  73. end if
  74. on error goto 0
  75.  
  76.  
  77.  
  78. if left(ServerName,1) = "\" then
  79.  
  80.     PublishPrinter ServerName, ServerName, Container
  81.  
  82. else
  83.  
  84.     on error resume next
  85.  
  86.     Set PrintServer = GetObject("WinNT://" & ServerName & ",computer")
  87.  
  88.     if err then
  89.         wscript.echo L_GetObjectError3_text & ServerName & ": " & err.Description
  90.         wscript.quit(1)
  91.     end if
  92.  
  93.     on error goto 0
  94.  
  95.  
  96.     For Each Printer In PrintServer
  97.         if Printer.class = "PrintQueue" then PublishPrinter Printer.PrinterPath, ServerName, Container
  98.     Next
  99.  
  100.  
  101. end if
  102.  
  103.  
  104.  
  105.  
  106. sub PublishPrinter(UNC, ServerName, Container)
  107.  
  108.     
  109.     Set PQ = WScript.CreateObject("OlePrn.DSPrintQueue.1")
  110.  
  111.     PQ.UNCName = UNC
  112.     PQ.Container = Container
  113.  
  114.     on error resume next
  115.  
  116.     PQ.Publish(2)
  117.  
  118.     if err then
  119.         if err.number = -2147024772 then
  120.             wscript.echo L_PublishError1_text & Chr(34) & ServerName & Chr(34) & L_PublishError2_text
  121.             wscript.quit(1)
  122.         else
  123.             wscript.echo L_PublishError3_text & Chr(34) & UNC & Chr(34) & "."
  124.             wscript.echo L_PublishError4_text & err.Description
  125.         end if
  126.     else
  127.         wscript.echo L_PublishSuccess1_text & PQ.Path
  128.     end if
  129.  
  130.     Set PQ = nothing
  131.  
  132. end sub
  133.